library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity seq_detector is 
port(clk,din:in std_logic;
	odd_t:out std_logic:='0';
	y:out std_logic
	);
end entity seq_detector;

architecture myfun of seq_detector is
	function ot(din:std_logic_vector) return std_logic;
	function ot(din:std_logic_vector) return std_logic is
	variable temp:std_logic;
	begin
	temp:='1';
	for i in 0 to 8 loop
		temp:=temp xor din(i);
	end loop;
	return temp;
	end function ot;
	type state is(idle,one,two,three,four,five,six,seven,eight,nine);
	signal ps,ns:state;
	constant rnum:std_logic_vector:="110011000";
	signal test:std_logic_vector(8 downto 0);
	begin
	p1:process(clk)is
	begin
	if(rising_edge(clk)) then 
		ps<=ns;
	end if;
	end process p1;
	p2:process(din,ps) 
	begin
	case ps is
		when idle=>
		y<='0';odd_t<='0';test(0)<=din;
			if din=rnum(0) then
				ns<=one;
			else
				ns<=idle;
			end if;
		when one=>
		y<='0';odd_t<='0';test(1)<=din;
			if din=rnum(1) then
				ns<=two;
			else
				ns<=idle;
			end if;
		when two=>
		y<='0';odd_t<='0';test(2)<=din;
			if din=rnum(2) then
				ns<=three;
			else
				ns<=idle;
			end if;
		when three=>
		y<='0';odd_t<='0';test(3)<=din;
			if din=rnum(3) then
				ns<=four;
			else
				ns<=idle;
			end if;
		when four=>
		y<='0';odd_t<='0';test(4)<=din;
			if din=rnum(4) then
				ns<=five;
			else
				ns<=idle;
			end if;
		when five=>
		y<='0';odd_t<='0';test(5)<=din;
			if din=rnum(5) then
				ns<=six;
			else
				ns<=idle;
			end if;
		when six=>
		y<='0';odd_t<='0';test(6)<=din;
			if din=rnum(6) then
				ns<=seven;
			else
				ns<=idle;
			end if;
		when seven=>
		y<='0';odd_t<='0';test(7)<=din;
			if din=rnum(7) then
				ns<=eight;
			else
				ns<=idle;
			end if;
		when eight=>
			test(8)<=din;
			if din=rnum(8) then
			ns<=nine;
			else
				ns<=idle;
			end if;
		when nine=>
			y<='1';
			odd_t<=ot(test);
			if din=rnum(0) then
				ns<=one;
				test(0)<=din;
			else
				ns<=idle;
			end if;
	end case;
	end process p2;

end architecture myfun;
